package com.http;

import org.json.JSONObject;

import com.android.ocean.util.net.NetConUtil;
import com.common.method.ServerPath;
import com.contact.ObjTool;

/**
 * 
 * @ClassName:ADListTask
 * @Description:TODO
 * @author zhuw
 * @date 2014-10-31 下午8:08:56
 */
public class CityIDTask extends BaseTask {
	public CityIDTask(NetCallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected Object doInBackground(Object... params) {
		try {
		
			String ip = NetConUtil.sendGetRequest(ServerPath.IP_PATH);
			boolean succesflag=false;
			if(ObjTool.isNotNull(ip)){
				String jsonStrCity=NetConUtil.sendGetRequest(ServerPath.CITY_PATH+ip);
				JSONObject jrcity = new JSONObject(jsonStrCity);
				String city= jrcity.optString("city");
				if(ObjTool.isNotNull(city)){
					JSONObject objParams = new JSONObject();
					objParams.put("catname", city + "");
					String jsonStr = NetConUtil.sendPostRequestByJson(
							ServerPath.CATID_PATH,
							objParams);
					JSONObject jr = new JSONObject(jsonStr);
					if (jr.getString("result").equals("1")) {
						succesflag=true;
						flag = FLAG_SUCCESS;
						result = jr.getJSONObject("data").opt("catid");
					} else {
						flag = FLAG_FAILED;
						result = jr.getJSONObject("data").getString("message");
					}


					
				}
			}
		if(succesflag){
			flag = FLAG_SUCCESS;
		} else {
			flag = FLAG_FAILED;
			result = "";
		}
			

		} catch (Exception e) {
			flag = FLAG_FAILED;
			result = failedStr;
		}
		return result;
	}
}
